package wtws.message.detail;

import java.nio.ByteBuffer;

import wtws.util.ByteUtil;

public class EllipseMicroBustProductSubBlock {

	public static final int MSG_LEN = 16;
	private int shapeAngularOrientation;
	private int centerPoint1XCoordinate;
	private int centerPoint1YCoordinate;
	private int majorAxis;
	private int minorAxis;
	private int convertedEstimateLoss;

	public EllipseMicroBustProductSubBlock() {

	}

	public EllipseMicroBustProductSubBlock(int x1, int y1, int majorAxis, int minorAxis, int loss, int shapeAngularOrientation) {
		this.centerPoint1XCoordinate = x1;
		this.centerPoint1YCoordinate = y1;
		this.majorAxis = majorAxis;
		this.minorAxis = minorAxis;
		this.convertedEstimateLoss = loss;
		this.shapeAngularOrientation = shapeAngularOrientation;

	}

	public byte[] toByteArray() {
		ByteBuffer br = ByteBuffer.allocate(MSG_LEN);
		br.put(ByteUtil.to2Bytes(centerPoint1XCoordinate / 15));
		br.put(ByteUtil.to2Bytes(centerPoint1YCoordinate / 15));
		br.put(ByteUtil.to2Bytes(majorAxis / 15));
		br.put(ByteUtil.to2Bytes(minorAxis / 15));
		int sao = (int)(shapeAngularOrientation / 0.00549);
		br.put(ByteUtil.to2Bytes(sao));
		char tenth = (char) ((int) (convertedEstimateLoss % 100) / 10 + '0');
		char oneth = (char) (convertedEstimateLoss % 10 + '0');
		br.put(ByteUtil.toByte(tenth));
		br.put(ByteUtil.toByte(oneth));
		return br.array();
	}

	public String toString() {
		StringBuffer buf = new StringBuffer();
		buf.append(centerPoint1XCoordinate);
		buf.append(",");
		buf.append(centerPoint1YCoordinate);
		buf.append(",");
		buf.append(majorAxis);
		buf.append(",");
		buf.append(minorAxis);
		buf.append(",");
		buf.append(convertedEstimateLoss);
		return buf.toString();
	}

	public int getShapeAngularOrientation() {
		return shapeAngularOrientation;
	}

	public void setShapeAngularOrientation(int shapeAngularOrientation) {
		this.shapeAngularOrientation = shapeAngularOrientation;
	}

	public int getCenterPoint1XCoordinate() {
		return centerPoint1XCoordinate;
	}

	public void setCenterPoint1XCoordinate(int centerPoint1XCoordinate) {
		this.centerPoint1XCoordinate = centerPoint1XCoordinate;
	}

	public int getCenterPoint1YCoordinate() {
		return centerPoint1YCoordinate;
	}

	public void setCenterPoint1YCoordinate(int centerPoint1YCoordinate) {
		this.centerPoint1YCoordinate = centerPoint1YCoordinate;
	}

	public int getConvertedEstimateLoss() {
		return convertedEstimateLoss;
	}

	public void setConvertedEstimateLoss(int convertedEstimateLoss) {
		this.convertedEstimateLoss = convertedEstimateLoss;
	}
}
